//添加规格
$('.addspecification').click(function() {
	if($('.specificationsParameter').length < 10){
		$('.specificationC').append('<div class="specificationsParameter"><input type="text"  class="specvalue"/><button class="del">删除</button></div>');
	}
})

//删除规格
$('.specificationC').on('click', '.del', function() {
	var index = $('.del').index($(this));
	$('.del').eq(index).parent().remove()
})

//添加修改的规格
$('.amendsubmit').click(function(){
	if($('.amendC_d').length<10){
		$('.amendC').append('<div class="flex main_zdy sideAlign_center amendC_d"><input type="text" /><div class="affirm">确认</div><div class="del">删除</div></div>')
	}
	
})

$('.navigation_n div').hover(function(){
	var index = $(this).index();
	if(index == 1){
		$('.navigation_n div ul li').click(function(e){
			e.stopPropagation();
			var index = $(this).index();
			if(index == 0){
				window.location.href = './firststep.html'
			}else if(index == 1){
				window.location.href = './specification.html'
			}else if(index == 2){
				window.location.href = './trademark.html'
			}
		})
	}else if(index == 2){
		$('.navigation_n div ul li').click(function(e){
			e.stopPropagation();
			var index = $(this).index();
			if(index == 0){
				window.location.href = '../indent/goodsindent.html'
			}else if(index == 2){
				window.location.href = '../indent/evaluate.html'
			}
		})
	}
})

var onegoods = $('#onegoods').html();
var oneGoods = Handlebars.compile(onegoods);
var onegoodid = '';
var twogoods = $('#twogoods').html();
var twoGoods = Handlebars.compile(twogoods);
var twogoodid = '';
//商品类别
$.ajax({
	type:'post',
	url:URL.interface.getCategoryList,
	dataType:'json',
	data:{
		level:1
	},
	success:function(e){
//		console.log(e.data);
		if(e.code == '10000'){
			$("#onegoodsL").html(oneGoods(e.data));
			pcode = $('#onegoodsL').find("option:checked").attr("id");
			onegoodid = $('#onegoodsL').find("option:checked").attr("codeid");
			$.ajax({
				type:'post',
				url:URL.interface.getCategoryList,
				dataType:'json',
				data:{
					pcode:pcode
				},
				success:function(e){
//					console.log(e)
					$("#twogoodsL").html(oneGoods(e.data));
					twogoodid = $('#twogoodsL').find("option:checked").attr("codeid");
				}
			})
			$('#onegoodsL').change(function() {
				pcode = $(this).find("option:checked").attr("id");
				$.ajax({
					type:'post',
					url:URL.interface.getCategoryList,
					dataType:'json',
					data:{
						pcode:pcode
					},
					success:function(e){
//						console.log(e)
						$("#twogoodsL").html(oneGoods(e.data));
						twogoodid = $('#twogoodsL').find("option:checked").attr("codeid");
					}
				})
			})
		}
	}
})

//添加规格
$('.submit').click(function(){
	var specvalue = [];
	//获取添加的规格值
	$(".specvalue").each(function(){
	    specvalue.push($(this).val());
	})
	if(String(specvalue) != '' && $('.specname').val().length != 0){
		$.ajax({
			type:'post',
			url:URL.interface.addspec,
			dataType:'json',
			data:{
				categoryFirstId:onegoodid,
				categorySecondId:twogoodid,
				name:$('.specname').val(),
				values:String(specvalue),
			},
			success:function(e){
				if(e.code == '10000'){
					alert('添加成功')
				}
			}
		})
	}else{
	}
})

var demo = $('#demo').html();
var demoPages = Handlebars.compile(demo);

//规格列表
$.ajax({
	type:"post",
	url:URL.interface.getCategoryProperty,
	dataType:'json',
	success:function(e){
		console.log(e)
		if(e.code == '10000'){
			var options={
				"id":"page",//显示页码的元素
				"data":e.property,//显示数据
			    "maxshowpageitem":3,//最多显示的页码个数
			    "pagelistcount":10,//每页显示数据个数
			    "callBack":function(result){
//			    	     var cHtml="";
//			        for(var i=0;i<result.length;i++){
//			            cHtml+='<div class="specificationlist_l flex main_zdy sideAlign_center"><div>'+result[i].name+'</div><div>'+result[i].propertyValueVos.value +'</div><div><button class="bth btn_specification" disabled="disabled">平台预设规格</button></div></div>'
//			        }
//			        $("#demoContent").html(cHtml);//将数据增加到页面中
					$("#demoContent").html(demoPages(e.property));
			    }
			};
			   page.init(e.property.length,1,options);
			   
			   
			   //删除规格
			   $('.del').click(function(){
			   		var id = $(this).attr("data_id");
			   		$.ajax({
			   			type:"post",
			   			url:URL.interface.delValue,
			   			dataType:'json',
			   			data:{
			   				valueId:id
			   			},
			   			success:function(e){
			   				console.log(e)
			   			}
			   		});
			   })
			   
		}
	}
});
